package space.edge.d.demo.qrcode.codescanner.scanner;

import space.edge.d.demo.qrcode.exception.ReaderException;
import space.edge.d.demo.qrcode.privatecode.CodeReader;

/**
 * Created by gsl on 2017/11/4.
 */

public class PrivateCodeReaderThread extends CodeThread {

    private CodeReader codeReader;

    PrivateCodeReaderThread(Object lockObj) {
        this.lockObj = lockObj;
        this.codeReader = new CodeReader();
    }

    @Override
    public void run() {
        while (!quit) {
            try {
                result = codeReader.decode(binaryBitmap, hints);
            } catch (ReaderException e) {
                result = null;
                e.printStackTrace();
            }
            if (latch.getCount() > 0)
                latch.countDown();
            else
                throw new IllegalStateException("CountDownLatch not reset");
            synchronized (lockObj){
                try {
                    lockObj.wait();
                } catch (InterruptedException e) {
                    // TODO: 2017/11/4 被唤醒，重新执行任务或者退出线程
                }
            }
        }
    }
}
